package com.bkgrands.fpmu.Adapters;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bkgrands.fpmu.R;
import com.bkgrands.fpmu.activities.MinorStagesActivity;
import com.bkgrands.fpmu.activities.MstagesActivity;
import com.bkgrands.fpmu.classes.Mstage;
import com.bkgrands.fpmu.classes.StaticFarm;

import java.util.List;

/**
 * Created by jeff on 7/13/19.
 */

public class MstagesAdapter extends RecyclerView.Adapter<MstagesAdapter.ViewHolder> {
    public List<Mstage> mstages;
    Context context;

    public MstagesAdapter(Context context, List<Mstage> payloads) {
        this.mstages = payloads;
        this.context = context;
    }
    @Override
    public MstagesAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.stage, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.tv_facility.setText(mstages.get(i).getName());
//        StaticFarm.currentMStage = this.mstages.get(i);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StaticFarm.currentMStage = MstagesAdapter.this.mstages.get(i);
                Intent intent = new Intent(v.getContext(), MinorStagesActivity.class);
                intent.putExtra( "majorsites", String.valueOf(mstages.get(i).getName()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mstages.size();
    }

    public void updateData(List<Mstage> mstages) {
        this.mstages = mstages;
        this.notifyDataSetChanged();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView tv_facility;
        public ViewHolder(View view) {
            super(view);

            tv_facility = (TextView)view.findViewById(R.id.stagename);

        }
    }

}
